<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8' />
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>

<body>
    <div id='map'></div>
    <script src="../libs/jquery.min.js"></script>
    <script type="text/javascript" src="../mapbox-gl-dev.js"></script>
    <script type="text/javascript" src="../iclient9-mapboxgl.js"></script>
    <script type="text/javascript">
        $.get(
            'http://iclsvr.supermap.io/iserver/services/map-mvt-California/rest/maps/California/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true&tileURLTemplate=ZXY',
            function (style) {
                var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
                //把背景设置透明方便看和天地图底图的叠加效果，也可直接把url传给map的style
                style.layers[0].paint["background-color"] = "rgba(168,209,221,=00)";
                //style.layers[1].paint["fill-color"] = "rgba(255,0,0,0.5)";
                map = new mapboxgl.Map({
                    container: 'map', // container id
                    renderWorldCopies: false,
                    isConstrain: true,
                    style: style,
                    center: [-122.2543440112645, 38.236059513982674],
                    zoom: 13,
                    crs: mapboxgl.CRS.EPSG4326
                });
                map.on('load', function () {
                    map.addLayer({
                        "id": "simple-tiles",
                        "type": "raster",
                        "source": {
                            "type": "raster",
                            "tiles": ['http://t0.tianditu.com/DataServer?T=vec_c&x={x}&y={y}&l={z}'],
                            "tileSize": 256
                        },
                        "minzoom": 0,
                        "maxzoom": 22
                    }, 'background')
                    //点选操作
                    map.addLayer({
                        "id": "line-highlighted",
                        "type": "line",
                        "source": "California",
                        "source-layer": "Trunk_L@California",
                        "paint": {
                            "line-color": "#0000ff",
                            "line-width": 10,
                            "line-opacity": 0.75
                        },
                        "filter": ["in", "NAME", ""]
                    }); 
                    map.on('click', function (e) {
                        var bbox = [
                            [e.point.x - 5, e.point.y - 5],
                            [e.point.x + 5, e.point.y + 5]
                        ];
                        var features = map.queryRenderedFeatures(bbox, {
                            layers: ["Trunk_L@California#6_1"]
                        });
                        console.log(features);
                        var filter = features.reduce(function (memo, feature) {
                            if (feature.properties.NAME) {
                                memo.push(feature.properties.NAME);
                            }
                            return memo;
                        }, ['in', 'NAME']);

                        map.setFilter("line-highlighted", filter);
                    });
                });
            })

    </script>

</body>

</html>
